# -*- coding: UTF-8 -*-
import os
import json

# 默认配置
config = {
    '考生姓名': '此处填写考生姓名',
    '考生编号': '此处填写15位考生编号',
    '身份证号': '此处填写完整身份证号',
    '密码': '此处填写学信网密码',
    '报考单位代码': '此处填写5位报考单位数字代码',
    '考生报名号': '此处填写9位考生报名号',
    '分钟延时': '此处填写分钟延时',
    '发件邮箱': '发件邮箱',
    '发件邮箱授权码': '发件邮箱授权码',
    '收件邮箱': '收件邮箱',
    '邮箱测试': 'True'
}


class Config:
    def __init__(self):
        pass

    # 生成默认配置模板
    def saveConfig(self):
        try:
            if not os.path.exists("config.json"):
                with open("config.json", "w", encoding='utf-8') as f:
                    json.dump(config, f, ensure_ascii=False, sort_keys=True, indent=4)
                    f.close()
            else:
                with open("config.json", "a", encoding='utf-8') as f:
                    json.dump(config, f, ensure_ascii=False, sort_keys=True, indent=4)
                    f.close()
            print("生成默认配置文件完成...")

        except Exception as e:
            print("生成默认配置失败==>", e)

    # 载入配置
    def loadConfig(self):
        dic = config
        try:
            if os.path.exists("config.json"):
                with open("config.json", 'rb') as f:
                    dic = json.load(f)
        except Exception as e:
            print("载入默认配置失败==>", e)

        print("载入配置成功")
        print("查询延时：" + dic['分钟延时'])
        return dic
    pass
